#include <iostream>
#include <vector>
#include <climits>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;
    vector<int> C(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> C[i];
    }
    vector<vector<int>> g(M);
    for (int i = 0; i < M; ++i)
    {
        int K;
        cin >> K;
        g[i].resize(K);
        for (int j = 0; j < K; ++j)
        {
            int a;
            cin >> a;
            g[i][j] = a - 1; // 转换为0-based索引
        }
    }

    long long min_cost = LLONG_MAX;
    int max_num = 1;
    for (int i = 0; i < N; ++i)
    {
        max_num *= 3;
    }

    for (int num = 0; num < max_num; ++num)
    {
        vector<int> x(N);
        int temp = num;
        for (int j = 0; j < N; ++j)
        {
            x[j] = temp % 3;
            temp /= 3;
        }

        bool valid = true;
        for (const auto &zoos : g)
        {
            int sum = 0;
            for (int zoo : zoos)
            {
                sum += x[zoo];
            }
            if (sum < 2)
            {
                valid = false;
                break;
            }
        }

        if (valid)
        {
            long long cost = 0;
            for (int j = 0; j < N; ++j)
            {
                cost += x[j] * C[j];
            }
            if (cost < min_cost)
            {
                min_cost = cost;
            }
        }
    }

    cout << min_cost << '\n';

    return 0;
}
